<template>
  <!-- <el-alert :closable="false">
      <router-view />
  </el-alert>-->
  <div style="padding:30px;width:60%">
    <el-form
      :model="ruleForm"
      :rules="rules"
      ref="ruleForm"
      label-width="115px"
      class="demo-ruleForm"
    >
      <el-form-item label="账号名称" prop="name">
        <el-col :span="22">
          <el-input v-model="ruleForm.name"></el-input>
        </el-col>
      </el-form-item>

      <el-form-item label="账号密码" prop="password">
        <el-col :span="22">
          <el-input type="password" v-model="ruleForm.password"></el-input>
        </el-col>
      </el-form-item>
      <el-form-item label="请确认密码" prop="rppassword">
        <el-col :span="22">
          <el-input type="password" v-model="ruleForm.rppassword"></el-input>
        </el-col>
      </el-form-item>
      <el-form-item label="分公司负责人" prop="person">
        <el-col :span="22">
          <el-input v-model="ruleForm.person"></el-input>
        </el-col>
      </el-form-item>
      <!-- 这里应该有个总公司的id的，可能是默认带了 -->
      <el-form-item label="负责人电话" prop="telephone">
        <el-col :span="22">
          <el-input v-model="ruleForm.telephone"></el-input>
        </el-col>
      </el-form-item>

      <el-form-item label="创建时间" required>
        <el-form-item prop="createTime">
          <el-col :span="22">
            <el-date-picker
              type="date"
              placeholder="选择日期"
              v-model="ruleForm.createTime"
              value-format="yyyy-MM-dd"
              style="width: 100%;"
            ></el-date-picker>
          </el-col>
        </el-form-item>
      </el-form-item>

      <!-- 
      <el-form-item label="是否执行" prop="flag">
        <el-col :span="22">
          <el-input v-model="ruleForm.flag"></el-input>
        </el-col>
      </el-form-item>-->
      <!-- 这里应该有个合同的主键的id的，可能是默认带了 -->
      <!-- 这里应该有个部门的的id的，可能是默认带了 -->

      <el-form-item>
        <el-button type="primary" @click="submitForm('ruleForm')">立即创建</el-button>
        <el-button @click="resetForm('ruleForm')">重置</el-button>
      </el-form-item>
    </el-form>
  </div>
</template>
<script>
import { hqfgs, tjht } from "@/api/ht";
import { getToken, gettype, getid } from "@/utils/auth";
import { tjgs } from "@/api/zuzhijiagou";
import axios from 'axios'
export default {
  name: "DragTable",

  data() {
    var validatePass2 = (rule, value, callback) => {
      if (value === "") {
        callback(new Error("请再次输入密码"));
      } else if (value !== this.ruleForm.password) {
        callback(new Error("两次输入密码不一致!"));
      } else {
        callback();
      }
    };

    return {
      list: null,
      ruleForm: {
        name: "",
        password: "",
        rppassword: "",
        person: "",
        telephone: "",
        id: getid(),
        // token: getToken(),
        // usertype: gettype()
      },

      rules: {
        name: [{ required: true, message: "请输入姓名", trigger: "blur" }],
        password: [{ required: true, message: "请输入密码", trigger: "blur" }],
        rppassword: [
          { required: true, validator: validatePass2, trigger: "blur" }
        ],
        person: [
          {
            required: true,
            message: "请输入分公司负责人的姓名",
            trigger: "blur"
          }
        ],
        telephone: [
          { required: true, message: "请输入手机号", trigger: "blur" },
          { min: 11, max: 11, message: "请输入11手机号", trigger: "blur" }
        ]
      }
    };
  },
  created() {
    // this.getList();
  },
  methods: {
    submitForm(formName) {
      var that=this
      this.$refs[formName].validate(valid => {
        if (valid) {
          alert("submit!");
            // 添加公司的方法
            axios.post('http://47.102.125.229:8888/branch/add', 
                {branch: that.ruleForm},
                {
                  headers:{
                     "Content-Type": "application/json",
                     'token': getToken(),
                     'type':1,
                  }
                },
                
          )

          // tjgs(that.ruleForm)
          //   .then(response => {
          //     console.log(response);            
          //     console.log(111111);           
          //   })
          //   .catch(e => {
          //     this.loading = false;
          //   });
        } else {
          console.log("error submit!!");
          return false;
        }
      });
    },
    resetForm(formName) {
      this.$refs[formName].resetFields();
    }
  }
};
</script>

<style scoped>
.sortable-ghost {
  opacity: 0.8;
  color: #fff !important;
  background: #42b983 !important;
}
/* .el-alert__content {
  width: 300px;
} */
</style>

<style scoped>
.icon-star {
  margin-right: 2px;
}
.el-alert__content {
  width: 50%;
}
.drag-handler {
  width: 20px;
  height: 20px;
  cursor: pointer;
}
.show-d {
  margin-top: 15px;
}
/* .el-alert__content {
  width: 300px;
} */
</style>
